<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .demo1,.demo2{
            width: 300px;
            background: #eee;
            height: 60px;
            position: relative;
            margin: 100px auto;
        }
        .demo1::before,
        .demo1::after{
            content: "";
            display: block;
            width: 0;
            height: 3px;
            background: red;
            position: absolute;
            bottom: 0px;
            left: 50%;
            transition: all .3s;
        }
        .demo1:hover::before{
            width: 50%;
            left: 0;
        }
        .demo1:hover::after{
            width: 50%;
            left: 100;
        }
        /* 方式2 */
        .demo2::after{
            content: "";
            display: block;
            width: 0%;
            height: 3px;
            background: red;
            position: absolute;
            bottom: 0px;
            left: 50%;
            /* transform: translateX(50%); */
            transition: all 10s;
        }
        .demo2:hover::after{
            width: 100%;
            left: 0%;
            /* transform: translateX(0%); */
        }
    </style>
</head>
<body>
    <div class="demo1"></div>
    <div class="demo2"></div>
</body>
</html>